#!/usr/bin/env python
# -*- coding: utf-8 -*-
from google.appengine.api import xmpp
from google.appengine.ext import webapp
from google.appengine.ext.webapp.util import run_wsgi_app
from dservice import DService


class XMPPHandler(webapp.RequestHandler):
    
    def post(self):
        message = xmpp.Message(self.request.POST)
        command=message.body.lower()
        dservice=DService(command)
        respons=dservice.parseCommand()
        if(respons<>[] and respons[0]<>'pass'):
            for re in reversed(respons):
                message.reply(re+'\n')
        else:
            message.reply('无效查询，请输入 ? 或 help 获取帮助')



application = webapp.WSGIApplication([('/_ah/xmpp/message/chat/', XMPPHandler)],
                                     debug=True)


def main():
  run_wsgi_app(application)

if __name__ == "__main__":
  main()        
